package com.jxau.mall.common.util;

import com.jxau.mall.common.enums.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: shop
 * @description: 统一异常处理的类
 * @author: guojiani
 * @create: 2025-04-17 15:02
 **/
@RestControllerAdvice //增强处理：给控制器增加一个功能
@Slf4j // log4j 日志
public class GlobleExceptionHandler {
    /**
     * 全局异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResponseVO exception(Exception e){
        log.error(e.getMessage(),e);// 打印异常
        // 处理异常
        return ResponseVO.fail(1000,e.getMessage());
    }
    /**
     * 参数类型错误
     * @param e
     * @return
     */
    @ExceptionHandler(HttpMediaTypeNotSupportedException.class)
    public ResponseVO
    httpMediaTypeNotSupportedException(HttpMediaTypeNotSupportedException e){
        log.error(e.getMessage(),e);// 打印异常
        // 处理异常
        return ResponseVO.fail(ResponseEnum.PARAM_TYPE_BIND_ERROR);
    }
}
